# 包含初始化数据库的脚本或函数
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from db.database import Base, engine

# 创建会话
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)


# 初始化数据库
def init_db():
    # 创建所有表
    Base.metadata.create_all(bind=engine)


# 执行脚本时初始化数据库
if __name__ == "__main__":
    with Session() as session:
        init_db()
        session.commit()
        session.close()
